<template>
	<view class="crm">
		<!-- <u-sticky> -->
		<view class="tops1">
			<view class="selectOptions">
				<view class="allyj" @click="showSel=true">
					{{changeReasonName?changeReasonName:'全部佣金'}}
					<u-icon class="u-m-l-8" name="arrow-down" color="#0F1417" size="24"></u-icon>
				</view>
				<!-- <view class="right" @click="show=true">
					{{!time?"全部日期":time}}
					<u-icon class="u-m-l-8" name="arrow-down" color="#0F1417" size="24"></u-icon>
				</view> -->
				<view class="right">
					
					<view @click="show=true" v-if="!time" class="">
						全部日期
						<u-icon class="u-m-l-8" name="arrow-down" color="#0F1417" size="24"></u-icon>
					</view>
					<view @click="clearTime" v-else class="">
				
				
						{{time}}
						<u-icon class="u-m-l-8" name="close-circle-fill" color="#0F1417" size="24"></u-icon>
					</view>
				</view>
			</view>

		</view>
		<view class="total" :style="{'margin-top': paddingTop}">	
		<view class="tit">
			<text>收益汇总</text>
			<text>
				{{addData.note}}
				
				<!-- 每月15-17日提现日，收益会暂时停止更新 -->
				</text>
			<view class="tag">
				每日数据
			</view>
		</view>
		<view class="Caculist">
			<view class="item">
				<view class="money">
					￥
					<u-count-to font-size="28" :decimals="2" bold color="#FA4A53 " :end-val="addData.totalAmount" separator=",">
					</u-count-to>
				</view>
				<view class="name">
					总收益
				</view>
			</view>
			<view class="item">
				<view class="money">
					<!-- {{addData.totalAmount}} -->
					￥	<u-count-to font-size="28" :decimals="2" bold color="#FA4A53" :end-val="addData.otherAmount1" separator=",">
					</u-count-to>
				</view>
				<view class="name">
					软件收益
				</view>
			</view>
			<view class="item">
				<view class="money">
					￥	<u-count-to font-size="28" :decimals="2" bold color="#FA4A53" :end-val="addData.otherAmount2" separator=",">
					</u-count-to>
				</view>
				<view class="name">
					团队奖励
				</view>
			</view>
		</view>
		<view class="Caculist u-m-t-40">
			<view class="item">
				<view class="money">
					￥	<u-count-to font-size="28" :decimals="2" bold color="#FA4A53" :end-val="addData.otherAmount3" separator=",">
					</u-count-to>
				</view>
				<view class="name">
					市级合伙人奖励
				</view>
			</view>
			<view class="item">
				<view class="money">
					￥	<u-count-to font-size="28" :decimals="2" bold color="#FA4A53" :end-val="addData.otherAmount4" separator=",">
					</u-count-to>
				</view>
				<view class="name">
					省级合伙人奖励
				</view>
			</view>
			<view class="item">
				<view class="money">
					￥	<u-count-to font-size="28" :decimals="2" bold color="#FA4A53" :end-val="addData.otherAmount5" separator=",">
					</u-count-to>
				</view>
				<view class="name">
					额外奖励
				</view>
			</view>
		</view>
		</view>
		<view v-if="list1.length" class="list">
			<view class="item" v-for="(item,index) in list1">
				<view class="sameStyle">
					<view class="left">
						{{item.changeReasonName}}
						<text>{{item.recordCode}}</text>
					</view>
					<view class="right">
						{{item.genTime}}
					</view>

				</view>
				<view class="u-m-t-20 sameStyle bot">
					<view class="left">
						订单金额：
						<text>￥{{item.changeOrderAmount}}</text>
					</view>
					<view class="right">
						结算收益：<text>￥{{item.commissionAmount}}</text>
					</view>

				</view>

			</view>
			<uni-load-more :status="status"></uni-load-more>
		</view>
		<view v-else class="empty" style="padding-top: 150px;">
			<view v-if="!list1.length && senDate" class="emptyAddress-box">
				<u-empty text="暂无内容" mode="news"></u-empty>
			</view>
		</view>

		<u-calendar active-bg-color="#FA4A53" btn-type="error" range-color="rgba(250, 74, 83, 0.4)" active-color="#fff"
			v-model="show" mode="range" @change="change"></u-calendar>

		<u-select @confirm="confirm" v-model="showSel" :list="sellist"></u-select>
	</view>
</template>

<script>

	export default {
		data() {
			return {
				sellist: [],
				showSel: false,
				addData: null,
				time: '',
				show: false,
				clearable: false,
				filterable: false,
				inputValue: '',

				barStyle: {
					'width': '96rpx',
					'height': '4rpx',
					'background': 'linear-gradient( 211deg, #EF8548 0%, #DE4543 100%)'
				},
				claName: '',
				checkAll: false,
				curId: '',
				curPhone: '',
				transferPhone: '',
				transferToAppMask: false,
				total: null, //总共多少条数据
				formData: {
					pageSize: 10, //每页10条数据
					page: 1, //第几页
					status: "",
				},

				status: "more",
				senDate: false,
				list1: [],
				changeReason: '',
				changeReasonName: '',
				paddingTop: "",
				entityCount: '',
				startDate: "",
				endDate: ""

			}
		},
		onReady() {
			uni.createSelectorQuery().select('.tops1').boundingClientRect((rect) => {
				console.log(rect.height, 66666);
				this.paddingTop = rect.height+16 + 'px'
			}).exec()
		},
		onLoad() {
			this.getreasonList()
			this.getlist()
		},
		onReachBottom() {
			let allTotal = this.formData.page * this.formData.pageSize;
			if (allTotal < this.total) {
				//当前条数小于总条数 则增加请求页数
				this.status = "loading"; //加载中状态
				this.formData.page++;
				this.getlist();
			} else {
				this.status = "noMore"; //加载完状态
				console.log("已加载全部数据");
			}
		},
		onPullDownRefresh() {
			this.formData.page = 1;
			// this.list1 = [];
			this.getlist('fresh');
		},
		methods: {
			clearTime() {
				this.time = ''
				this.startDate = ''
				this.endDate = ''
				this.getlist('fresh');
			},
			// 佣金来源分类查询
			getreasonList(){
				this.$u.api
					.reasonList({
				commissionType:'SOFT'
			})
					.then((res) => {
						console.log(res,666666);
						this.sellist = res?.data?.map(r=>{
							return{
								...r,
								value:r.changeReason,
								label: r.changeReasonName
							}
						})
						
						this.sellist.unshift({
							value:'',
							label:'全部佣金'
						})
						
						
					});
				
			},
			confirm(e) {
				this.changeReason=e[0]?.value
				this.changeReasonName=e[0]?.label
				// this.formData.page = 1;
				// this.list1 = [];
				// this.getlist();
				
				this.formData.page = 1;
				this.getlist('fresh');
			},
			change(e) {
				console.log(e);
				this.time = e.startYear + '/' + e.startMonth + '/' + e.startDay + '~' + e.endYear + '/' + e.endMonth +
					'/' + e.endDay
				this.startDate = e.startDate
				this.endDate = e.endDate
				// this.formData.page = 1;
				// this.list1 = [];
				// this.getlist();
				
				this.formData.page = 1;
				this.getlist('fresh');

			},
			// 状态：ENABLE正常，EXPIRE已过期，DISABLE已停用
			GetcardTypeCodeColor(item) {
				if (item.status == 'ENABLE') {
					return 'base'
				} else if (item.status == 'EXPIRE') {
					return 'ending'
				} else {
					return 'over'
				}
			},

			search() {
				// this.formData.page = 1
				// this.list1 = []
				// this.getlist()
				
				this.formData.page = 1;
				this.getlist('fresh');
			},
			getlist(type) {
				this.senDate = false;
				let query = {
					pageIndex: this.formData.page,
					pageSize: this.formData.pageSize,
					commissionType: "SOFT",
					changeReason: this.changeReason,
					startDate: this.startDate,
					endDate: this.endDate
				}

				this.$u.api
					.commissionPage(query)
					.then((res) => {
						if(type=='fresh'){
							this.list1 = [];
						}
						this.senDate = true;
						if (res.code == 'ok') {
							this.addData = res?.data?.addData
							this.total = res.data.entityCount;
							const newlist = res.data.entities;
							this.list1.push(...newlist);
							if (this.list1.length < this.formData.pageSize) {
								this.status = "noMore"; //加载完状态
							}
						} else {}
						uni.stopPullDownRefresh()
						uni.hideLoading();
					});
			},

			godetail(e) {
				uni.navigateTo({
					url: "/subPack/order/detail?id=" + e.orderNo
				})
			}
		}
	}
</script>

<style>
	page {
		background: #F6F6F6;
	}
</style>
<style scoped lang="scss">
	.crm {
		padding: 0 0 24rpx;

		.total {
			margin: 0 32rpx 20rpx;
			padding: 24rpx 32rpx;
			background: #fff;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			.tit{
				margin-bottom: 32rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				>text:nth-child(1){
					font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
					font-weight: 500;
					font-size: 28rpx;
					color: #FA4A53;
					line-height: 39rpx;
				}
				>text:nth-child(2){
				font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
				font-weight: 400;
				font-size: 20rpx;
				color: #A6A6A6;
				line-height: 24rpx;
				margin-left: 8rpx;
				}
				.tag{
					font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
					font-weight: 400;
					font-size: 20rpx;
					color: #0F1417;
					line-height: 24rpx;
					display: flex;
					align-items: center;
					justify-content:center;
					width: 96rpx;
					height: 40rpx;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					border: 2rpx solid #E7E7E7;
				}
			}
			.Caculist{
				display: flex;
				align-items: center;
				justify-content: space-between;
				>view{
					flex: 1;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					.money{
						font-family: HarmonyOS Sans SC, HarmonyOS Sans SC;
						font-weight: 500;
						font-size: 20rpx;
						color: #FA4A53;
						line-height: 23rpx;
					}
					.name{
						font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
						font-weight: 400;
						font-size: 26rpx;
						color: #1D2129;
						line-height: 30rpx;
						margin-top: 14rpx;
					}
				}
			}
		}


		.tops1 {
			background: #FFFFFF;
			position: fixed;
			left: 0;
			top: 0;
			right: 0;
			z-index: 9;
		}

		.selectOptions {
			border-bottom: 2rpx solid #E7E7E7;
			padding: 20rpx 40rpx 14rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.allyj {
				font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
				font-weight: 400;
				font-size: 28rpx;
				color: #0F1417;
				line-height: 40rpx;
				flex: 1;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.right {
				flex: 1;
				font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
				font-weight: 400;
				font-size: 28rpx;
				color: #0F1417;
				line-height: 40rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;

				text {
					color: #0F1417;
				}
			}
		}

		.list {
			// border-radius: 16rpx 16rpx 16rpx 16rpx;
			
			margin: 0 32rpx ; 
			// padding: 0 40rpx;

			.item {
				background: #fff;
				padding: 24rpx;
				margin-bottom: 24rpx;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				// border-bottom: 2rpx solid #F6F6F6;

				// margin-bottom:24rpx;
				// padding: 0 24rpx;
				// background: #FFFFFF;
				// border-radius: 16rpx 16rpx 16rpx 16rpx;
				.sameStyle {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.left {
						font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
						font-weight: 500;
						font-size: 28rpx;
						color: #0F1417;
						line-height: 40rpx;
						text{
							font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
							font-weight: 400;
							font-size: 24rpx;
							color: rgba(15,20,23,0.4);
							line-height: 36rpx;
							margin-left: 20rpx;
						}

						.status {
							padding-left: 16rpx;
							font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
							font-weight: 500;
							font-size: 28rpx;
							color: #6F7274;
							line-height: 33rpx;

							&.add {
								color: rgba(23, 103, 222, 1) !important;
							}

							&.doing {
								color: #FFA340 !important;
							}

							&.ok {
								color: #1BAB6B !important;
							}
						}
					}

					.right {
						font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
						font-weight: 400;
						font-size: 24rpx;
						color: rgba(15,20,23,0.4);
						line-height: 36rpx;
					}

				}

				.bot {

					.left,
					.right {
						font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
						font-weight: 400;
						font-size: 28rpx;
						color: rgba(15,20,23,0.7);
						line-height: 40rpx;
						text{
							font-size: 28rpx !important;
							color: #FA4A53;
						}
					}
				}

			}
		}


		.tags {
			font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
			font-weight: 400;
			font-size: 20rpx;
			margin-left: 8rpx;
			line-height: 20rpx;
			padding: 4rpx 10rpx;
			border-radius: 14rpx 14rpx 14rpx 14rpx;
			color: #fff;

			&.base {
				color: #FFFFFF !important;
				background: #1BAB6B !important;
			}

			&.over {
				// color: #FFE1CF !important;
				background: #6F7274 !important;
			}

			&.ending {
				color: #FFE1CF !important;
				background: #FA4A53 !important;
			}


		}


		.borderGap {
			// margin-bottom: 8rpx;
			border-bottom: 2rpx solid #E7E7E7;
			margin-top: -4rpx;

		}

	}
</style>
